﻿package org.cubeland.game.core.drawing.yuki 
{
	import org.papervision3d.materials.BitmapColorMaterial;
	import org.papervision3d.materials.MovieMaterial;
	import org.papervision3d.materials.utils.MaterialsList;
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.objects.primitives.Cube;
	
	import caurina.transitions.Tweener;
	
	/**
	 * CubeLand.org Game
	 * @author Duarte Peixinho
	 */
	public class DrawYukiEyes extends DisplayObject3D
	{
		private var _leftEye:Cube;
		private var _rightEye:Cube;
		private var _rightEyeBall:DrawYukiEyeBalls;
		private var _leftEyeBall:DrawYukiEyeBalls;
		
		public function DrawYukiEyes() 
		{
			init();
		}
		
		private function drawMaterials(eye:DrawYukiEyeBalls):MaterialsList {		
			
			var mvm:MovieMaterial = new MovieMaterial(eye);
			mvm.smooth = true;
			mvm.animated = true;
			
			var m:MaterialsList = new MaterialsList( { 
				front:new BitmapColorMaterial(0xFFFFFF),
				back:mvm,
				right:new BitmapColorMaterial(0x000000),
				left:new BitmapColorMaterial(0x000000),
				top:new BitmapColorMaterial(0x000000),
				bottom:new BitmapColorMaterial(0x000000)
			} );			
			return m;
		}
		
		public function rotateEyes(angle:Number):void {
			_leftEye.localRotationZ = -angle;
			_rightEye.localRotationZ = angle;
		}
		
		public function init():void {
			// left eye
			_leftEyeBall = new DrawYukiEyeBalls();			
			_leftEye = new Cube(drawMaterials(_leftEyeBall), 40, 5, 50);					
			
			_leftEye.x -= 35;
			_leftEye.localRotationX = 5;
			_leftEye.localRotationY = 10;

			addChild(_leftEye);
			
			// right eye
			_rightEyeBall = new DrawYukiEyeBalls();
			_rightEye = new Cube(drawMaterials(_rightEyeBall), 40, 5, 50);			
			
			_rightEye.x += 35;
			_rightEye.localRotationX = 5;
			_rightEye.localRotationY = -10;

			addChild(_rightEye);	
		}
		
		public function lookCenter():void {
			Tweener.addTween(_leftEyeBall.eyeBall, { x:_leftEyeBall.position.x, y:_leftEyeBall.position.y, transition:"linear", time:1 } );
			Tweener.addTween(_rightEyeBall.eyeBall, { x:_rightEyeBall.position.x, y:_rightEyeBall.position.y, transition:"linear", time:1 } );
		}
		
		public function lookLeft():void {
			Tweener.addTween(_leftEyeBall.eyeBall, { x:5, y:_leftEyeBall.position.y, transition:"linear", time:1 } );
			Tweener.addTween(_rightEyeBall.eyeBall, { x:5, y:_rightEyeBall.position.y, transition:"linear", time:1 } );	
		}
		
		public function lookRight():void {
			Tweener.addTween(_leftEyeBall.eyeBall, { x:35, y:_leftEyeBall.position.y, transition:"linear", time:1 } );
			Tweener.addTween(_rightEyeBall.eyeBall, { x:35, y:_rightEyeBall.position.y, transition:"linear", time:1 } );	
		}
		
		public function lookUp():void {
			Tweener.addTween(_leftEyeBall.eyeBall, { x:_leftEyeBall.position.x, y:10, transition:"linear", time:1 } );
			Tweener.addTween(_rightEyeBall.eyeBall, { x:_rightEyeBall.position.x, y:10, transition:"linear", time:1 } );
		}	
		
		public function lookDown():void {
			Tweener.addTween(_leftEyeBall.eyeBall, { x:_leftEyeBall.position.x, y:40, transition:"linear", time:1 } );
			Tweener.addTween(_rightEyeBall.eyeBall, { x:_rightEyeBall.position.x, y:40, transition:"linear", time:1 } );
		}
		
		public function happy():void {
			
		}
		
		public function sad():void {
			
		}
		
	}

}